/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.ban.data.exchange.runner.tokenBucket.util;

import java.util.HashMap;

/**
 *
 * @author zwlin
 */
public final class Certs {

    public static final char[] getKeyPasswd() {
        return "123456".toCharArray();
    }

    public static final char[] getKeyStorePasswd() {
        return "123456".toCharArray();
    }

    public static final char[] getTrustStorePasswd() {
        return "123456".toCharArray();
    }

    public static final byte[] getServerPublicKeystoreBytes() {
        return Trans(ServerPubCert);
    }

    public static final byte[] getClientPrivatKeystoreBytes() {
        return Trans(ClientPriCert);
    }

    private static final char[] HEX_CHS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    private static final HashMap<Character, Byte> HEX_MAP;

    static {
        HEX_MAP = new HashMap<>();
        HEX_MAP.put('0', (byte) 0x00);
        HEX_MAP.put('1', (byte) 0x01);
        HEX_MAP.put('2', (byte) 0x02);
        HEX_MAP.put('3', (byte) 0x03);
        HEX_MAP.put('4', (byte) 0x04);
        HEX_MAP.put('5', (byte) 0x05);
        HEX_MAP.put('6', (byte) 0x06);
        HEX_MAP.put('7', (byte) 0x07);
        HEX_MAP.put('8', (byte) 0x08);
        HEX_MAP.put('9', (byte) 0x09);
        HEX_MAP.put('a', (byte) 0x0a);
        HEX_MAP.put('b', (byte) 0x0b);
        HEX_MAP.put('c', (byte) 0x0c);
        HEX_MAP.put('d', (byte) 0x0d);
        HEX_MAP.put('e', (byte) 0x0e);
        HEX_MAP.put('f', (byte) 0x0f);
    }

    public static final String Trans(byte[] bs) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bs) {
            sb.append(HEX_CHS[(b >>> 4) & 0x0f]).append(HEX_CHS[b & 0x0f]);
        }
        return sb.toString();
    }

    public static final byte[] Trans(String str) {
        byte[] bs = new byte[str.length() / 2 + str.length() % 2];
        boolean first = true;
        byte b = 0;
        int idx = 0;
        for (char c : str.toCharArray()) {
            if (first) {
                b = (byte) (HEX_MAP.get(c) << 4);
                first = false;
            } else {
                b |= HEX_MAP.get(c);
                bs[idx++] = b;
                first = true;
            }
        }
        if (idx < bs.length && first) {
            bs[idx] = b;
        }
        return bs;
    }

    private static final String ServerPubCert = "feedfeed000000020000000100000002000b6e6577735f736572766572000001600698011b0005582e353039000003453082034130820229a00302010202040fa44657300d06092a864886f70d01010b05003050310b300906035504061302434e310b300906035504081302424a310b300906035504071302424a310c300a060355040a1303494944310b3009060355040b13024449310c300a060355040313034949453020170d3137313132393037303434375a180f32313137313130353037303434375a3050310b300906035504061302434e310b300906035504081302424a310b300906035504071302424a310c300a060355040a1303494944310b3009060355040b13024449310c300a0603550403130349494530820122300d06092a864886f70d01010105000382010f003082010a0282010100acae947da9597e40bbfd32e828938d3c74183b5ebe6f0a14f12f905b35d86aa4157b2d5675f791930a6ece139343d813611201026597c4730e2c6050b3dc10fd3bc24c63c160edaea124048f6262cf72a6b50b8abbe9352161867a31dbb0ac7c0f4c63c9fb4e6e6f90af65496238880d51a0e718fb591f8876cd59a328422c98f416a8d7786bb4520104f5288e98f12be8908bba5e932c9dd99951432c27b2e1206b65c487ebb0730228eaafb38ae6944b658a3462397e7917ee3290ca919a329a96d971d1505fb502adbd09bd6d465f728cc7e32935c3b5c98ea13ca03328a9b11ef4d1fe0bb313dd4a376a393a73701f7ad165f0157410deea52a090adbed50203010001a321301f301d0603551d0e041604148a09cc387fd2016dfe733b12d5b1eb703034de1b300d06092a864886f70d01010b050003820101007fab139638e5d9b373468a33e03838391e59111a5837190a492ae7cc32709a24febc21bf8aa3ad9afa7c983234d12c699b0093b5cce95ae3c2115f61ce38501eb428d9ebf5c3b4e9f7db0ca1c40af6c0910c623f8b36137bd12fd0a33738fa027675988d9da982065fb0492dbb22356be1c869833c48526096201adaa41e50bf5ee18e9a6a31441869f04b008e1702c413aed56c7c4646db51d40454bf2daa9ff90504b4754845ad1d97842baf371a19fb63061cb5b6ab7f38d1d5f8e00c7adf25877528e3c95d4166e9e70dc7e9f708d853592dd94966c11115c324009ea17215ff689278ddb2007c4ce2fd37035a8bc76dbaa462e7cf6532e5b7e95ceff7efd54d1787fe899b605157e1c15998664dd5f04e34";
    private static final String ClientPriCert = "feedfeed000000020000000100000001000b6e6577735f636c69656e74000001600696bfee00000501308204fd300e060a2b060104012a021101010500048204e972d2e8deb9470e7d2a53f856a1fd7d98c74757117909924049a44b5d53e7c17e7510593e2de767b935b11d77f861e57564cec126ba3b69b9cf5c7ff2079dc17549befba5b85a1484746590d558aef97a747c72fb317b03a5b08dcd360c345763d3057b2dff07acd0e7e5e4cdde010be6cb80988756a32a758f48f9ec5eaf5d6cea92f78b922adfc51691b7b118b4b750113543f4e652d149ea352933ffde00933cfa19b07266b0d772a6bdd9d44904c618bdcab8bc22666f556bdea8c12b5a9183427560927cbd1f2ab345a23633409265e0e866cc623fcb50dbda62c265eeeb7053debe70664b6b5eb1cf6a4621004a8eb82dcd078991c8937fad017b432097df1543dfed9c588657072073c10842dcf0f20a8e2c79913c48ac88eb01e3994bf6f47ec93e36459e5e6ca6828eb6066e0c71d089840af2eae511e0ecc573c640ec78f53c11da0cdd4f6d89cda2974f47cbfbc44caefa64d4a5f55418cf90f2547ddf92bb38d9a48acea58ddcacbfd4baa156d3e087d589ab4b395b42c3a3daa7d88117febfe6b88bd08e8a52b74a3cf40d605c5e5809fb221829f0c2ebe8ba8189d632e73ec2f8594d55368a6bfa819a6e16ceeef9584e3a217b0b422c8e8f72d3a45b6cd15c5ff12dd131ac8561df7d497831c8bf1abca81efa8fe2eb9710a35bf0adcf55aa35546f6ccfa8aa72b8aa6e6db629940b45700b33842850364239e9afc08908ab34de63317e2458e7d2eb9dcd8f3df0bbea1e36f83cdff219d6b57416479a11d3ff48f912d425a279b81e4dfe4022c7ef34567a13c5d6b72d6a8a062fc8c4bce54d5dd7e99cd2b03246a930c707b2173b5db7752c9eb66c1cb66d2148fff043ea33a6bcd22e4a6d4c813b27b112082e4ad55dfd17ac04c9802a06e5fe85f2d61667f43ca3352bc357c18157c17531219c7f093341df9da9bdc360820ace373a6bd06970d9184b8d630cf5a58782bc8323c5b2a076456768efb920c97afcb203c4a4b2addf44da08f64dbf1703c1b443ebfa0c29173af2de901246394279f4baf47b6f19818d3b21fa9c7128525706e889ea09bb2231f2c91971e2e29652a0650cbb2ee47a5223e7d73f92dc7fb78313e3c95a54d84e5a6bf5b5f33bf3f468eaec186d5b1bb04ec147e9c9818d40ad21c9a1869aadc7d182b9a1a39e5a59e9a62a70c5159edfcc350722ec4d1efb3f077a589de622794d98c1925757669296ddcf0574d96bd0e6cdf72d301a7494f0358f0089b7ee85428cca36e79e5376ea2b74853e84b4787f11e5519d38f6a4cd732b02346053ee7f3b9a389a8d37ec877806063b4cc8abc19022de9ae557ac5544a10114187618d998dfefc8c4f7e8091746c097cdd3a6685ab0f4a824d173559a4791100c9d88bec4959ae169803d25275fa238016ec0a43ba923532a450c79a06eeb89a40bb8d0302308be69c56107a73800ede69aaab7affacf39592b81a0012cb779f6f71e72803dd0fd297e12fcd8c8f576f4443c82febe83d490fb0a6bc7da8284815711f168d94e0fd7a6daa7716d572197ccf24f0688071824be40a527d4400bea5e01c2c6e78fae94cb36c0a976ce9fcdad7cdc7a094dc9d5f95fc6fa141be79f2501fa51cb6ed80b220e625f58c1b8d10d7d2223ad48ad912ca8fc7bfc3dbb9e7c2c1fbcd373c163085e4fe6889f06eac24d98c2f4cf51a5866f5528ff29d255ce8c9c6bbd25ddc4456710aff2ff0071998ff78da54460edf99a2b1d5217b262787b71eb7c18f40b72193f27d9eac88c000000010005582e353039000003453082034130820229a00302010202040e2803d2300d06092a864886f70d01010b05003050310b300906035504061302434e310b300906035504081302424a310b300906035504071302424a310c300a060355040a1303494945310b3009060355040b13024449310c300a060355040313034949453020170d3137313132393037303335305a180f32313137313130353037303335305a3050310b300906035504061302434e310b300906035504081302424a310b300906035504071302424a310c300a060355040a1303494945310b3009060355040b13024449310c300a0603550403130349494530820122300d06092a864886f70d01010105000382010f003082010a0282010100889d6acbf5ac750b09d24caf0b21e03cb394bf4894f6dbf81987df0347bf3be4b5451cab05b4549222d54a225b3720a28236c4b2675f19da99b59bac3492fb766ae61335754dc2f1bc710898f3bc4a24f11e8baf73a8d87b773ea58c28872adc407600e1b9025e988e79dfbff09cb05f7b52d5e469d93953216bb0b0f09f74a54446e37f803efb16fd7aa3e17d4fb4a3c7c4c40a6717bc860845e266d0691d2145cfac7c60ec8331afcbfcc887047923d063279346a79fc47acd90be4a02c6ffe621ecc553b65d01663f8830d492da59fb5e676c030a65839282b285f1b670223c710210b059c95e90aaaa46a4b07ca03a76983f47361b89cfa1a7b101cc59f50203010001a321301f301d0603551d0e04160414f4d8798b25331a6fedd16194da26ddb949c41c60300d06092a864886f70d01010b0500038201010034aafdcfacc9041353bd9a2ce1c6599c4925051d3576f5fd332f7ded006d9c27d86b63857dd24e447d6008cee6d02062b3b4a83d9c5c039086ade8976df0793b497e2fc0614b2de4b894b8c033ce146fadc80e24eaa73bd5ef5fd08ee4acabb85b6e6ce3d328c69083bfec3e0704ebdd1db0d7a454e28c21de9b67fe645e72640e147d577da7218d939a5a20c42b5fb14b6b280b7fe1a6b1d66369d9bf82926b9e34bd5ac9fe94b524022a6816650b484b4f75af3819a6c12206425c8d6a0d165e54f8350adaac147847cc14ee1d700b66ec230ca1e638feb60f00a610aeccd4810a9616004bdcc4e04424e190fb10bf5db81fda6b37e305faa2f09b137927064975cd67f3530150c3c812ea6dc24b70702ce3ee";
}
